package com.yedean.controller;

import com.yedean.constants.SystemCode;
import com.yedean.operator.service.IEnterpriseAccountService;
import com.yedean.shop.service.IStoreManagerService;
import com.yedean.utils.Result;
import com.yedean.utils.ResultCode;
import com.yedean.vo.LoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * LoginController
 *
 * @author yedean
 * @date 2022/9/15
 */
@RestController
@Slf4j
@Api("登录接口")
public class LoginController {

    @Reference(version = "1.0.0", check = false)
    private IEnterpriseAccountService enterpriseAccountService;

    @Reference(version = "1.0.0", check = false)
    private IStoreManagerService storeManagerService;

    @ApiOperation(value = "登录入口")
    @ApiImplicitParam(name = "Authorization", value = "jwt token", required = false, dataType = "String", paramType = "header")
    @PostMapping("/enterpise/login")
    public Result login(@RequestBody LoginVO loginVO) {

        switch (loginVO.getType()) {
            case SystemCode.USER_TYPE_SHOP:
                return enterpriseAccountService.login(loginVO.getShopId(), loginVO.getPhone(), loginVO.getPassword());
            case SystemCode.USER_TYPE_STORE_MANAGER:
                return storeManagerService.login(loginVO.getShopId(), loginVO.getPhone(), loginVO.getPassword());
            default:
                Result result = new Result();
                result.setStatus(ResultCode.error);
                result.setDesc("不支持当前用户类型登录");
                return result;
        }
        
    }
}
